package com.jd.finance.core.controller.api;


import com.jd.finance.core.service.LoanService;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 贷款表 前端控制器
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-17
 */
@Api(tags = "贷款中心")
@Slf4j
@RestController
@RequestMapping("/api/core/loanCenter")
public class LoanController {

    @Resource
    private LoanService loanService;

    @ApiOperation("查询贷款记录")
    @GetMapping("/getLoanRecord")
    public BaseResult getLoanRecord(Integer uid) {
        if (uid == null) {
            log.error("查询贷款记录,uid为空!");
            return BaseResult.error().message("uid为空!");
        }
        return loanService.selectLonInfo(uid);
    }

    @ApiOperation("重新申请贷款，就在之前的贷款申请数据上修改，更新基本字段，审核字段清空，返回是否成功")
    @PostMapping("/secondLoanApply")
    public BaseResult secondLoanApply(Integer lid, Integer uid, Integer workId,
                                      Integer bcId, String proName,
                                      String bankName, String loanReason,
                                      BigDecimal loanMoney, BigDecimal allDebt) {
        if (lid == null) {
            log.error("查询贷款记录,lid为空!");
            return BaseResult.error().message("lid为空!");
        }
        return loanService.secondLoanApply(lid, uid, bcId, workId, proName, bankName, loanReason, loanMoney, allDebt);
    }


}

